package com.easysoft.framework.logs.service;

import com.easysoft.commons.utils.DateTimeUtils;
import com.easysoft.commons.utils.UUIDUtils;
import com.easysoft.framework.annotation.jdbc.DataSource;
import com.easysoft.framework.beans.Page;
import com.easysoft.framework.logs.mapper.SysLogsMapper;
import com.easysoft.framework.logs.mapper.SysLogsMapperExtd;
import com.easysoft.framework.logs.model.SysLogs;
import com.easysoft.framework.logs.model.SysLogsQuery;
import com.easysoft.framework.logs.model.SysLogsView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service("service.SysLogsService")
public class SysLogsService {

    @Autowired
    @Qualifier("mapper.SysLogsMapperExtd")
    private SysLogsMapperExtd sysLogsMapperExtd;


    @Autowired
    @Qualifier("mapper.SysLogsMapper")
    private SysLogsMapper sysLogsMapper;

    @DataSource(DataSource.SLAVE)
    public List<SysLogsView> selectSysLogsByPage(Page page, SysLogsQuery query){
        int maxRow = sysLogsMapperExtd.selectCountAllSysLogs(query);
        if (maxRow == 0){
            return new ArrayList<SysLogsView>();
        }
        page.setMaxRow(maxRow);
        return  sysLogsMapperExtd.selectSysLogsByPage(page,query);
    }

    /**
     * 插入日志
     * @param sysLogs
     * @return
     */
    @DataSource(DataSource.MASTER)
    public  int addSysLogs(SysLogs sysLogs){
        sysLogs.setId(UUIDUtils.getUUID());
        sysLogs.setCreateTime(DateTimeUtils.getCurrentDate());
        return  sysLogsMapper.insertSelective(sysLogs);
    }

}
